import { NestFactory } from '@nestjs/core';
import { AppModule } from './app.module';
import { HttpFilterFilter } from './common/http-filter/http-filter.filter';
import { join } from 'path';
import { NestExpressApplication } from '@nestjs/platform-express';
async function bootstrap() {
  const app = await NestFactory.create<NestExpressApplication>(AppModule);
  // 注册全局守卫，JwtAuthGuard 会对 /api 路径开头的路由生效
  app.useGlobalFilters(new HttpFilterFilter());

  // 启用 CORS
  app.enableCors({
    origin: '*', // 允许所有域名的跨域请求
    methods: 'GET,HEAD,PUT,PATCH,POST,DELETE', // 允许的 HTTP 方法
    allowedHeaders: ['Authorization', 'Content-Type'], // 添加 Authorization
    credentials: true, // 如果允许携带 Cookie
  });

  app.useStaticAssets(join(__dirname, '..', 'uploads'), {
    prefix: '/uploads/', // URL 前缀
  });

  await app.listen(process.env.PORT ?? 3000);
}
bootstrap();
